package com.foreknow.hospital.controller;

import com.foreknow.hospital.po.User;
import com.foreknow.hospital.service.UserService;
import com.foreknow.hospital.service.impl.UserServiceImpl;
;

import javax.servlet.http.HttpServletRequest;

/**
 * 根据手机号码和密码进行登录验证
 * http://localhost:8080/tijian/UsersController/getUsersByUserIdByPass?userId=12345671111&password=123
 */
public class UserController {
    public Object getUsersByUserIdByPass(HttpServletRequest request) {
        UserService usersService = new UserServiceImpl();
        User users = new User();
        String userId = request.getParameter("userId");
        String password = request.getParameter("password");
        User user = usersService.getUsersByUserIdByPass(userId, password);
        return user;
    }
    public Object saveUsers(HttpServletRequest request) {
        UserService usersService = new UserServiceImpl();
        User users = new User();
        users.setUserId(request.getParameter("userId"));
        users.setPassword(request.getParameter("password"));
        users.setRealName(request.getParameter("realName"));
        users.setSex(Integer.parseInt(request.getParameter("sex")));
        users.setIdentityCard(request.getParameter("identityCard"));
        users.setBirthday(request.getParameter("birthday"));
        int result = usersService.saveUsers(users);
        return result;
    }

    /**
     * 根据手机号码进行是否已注册验证
     * http://localhost:8082/tijian/UsersController/getUsersById?userId=12345671111
     * @param request
     * @return
     */
    public Object getUsersById(HttpServletRequest request) {
        UserService usersService = new UserServiceImpl();
       // String userId = request.getParameter("userId");
        User users = new User();
        users.setUserId(request.getParameter("userId"));
         users = usersService.getUsersById(users);
        return users;
    }

}
